package com.ruoyi.device.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.device.domain.DeviceState;
import com.ruoyi.device.service.IDeviceStateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备状态列表Controller
 * 
 * @author ruoyi
 * @date 2022-12-11
 */
@Controller
@RequestMapping("/device/state")
public class DeviceStateController extends BaseController
{
    private String prefix = "device/state";

    @Autowired
    private IDeviceStateService deviceStateService;

    @RequiresPermissions("device:state:view")
    @GetMapping()
    public String state()
    {
        return prefix + "/state";
    }


    @GetMapping("/dynamic")
    public String dynamic() {
        return prefix + "/dynamic";
    }

    /**
     * 查询设备状态列表列表
     */
    @RequiresPermissions("device:state:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DeviceState deviceState)
    {
        startPage();
        List<DeviceState> list = deviceStateService.selectDeviceStateList(deviceState);
        return getDataTable(list);
    }

    /**
     * 导出设备状态列表列表
     */
    @RequiresPermissions("device:state:export")
    @Log(title = "设备状态列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DeviceState deviceState)
    {
        List<DeviceState> list = deviceStateService.selectDeviceStateList(deviceState);
        ExcelUtil<DeviceState> util = new ExcelUtil<DeviceState>(DeviceState.class);
        return util.exportExcel(list, "设备状态列表数据");
    }

    /**
     * 新增设备状态列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备状态列表
     */
    @RequiresPermissions("device:state:add")
    @Log(title = "设备状态列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DeviceState deviceState)
    {
        return toAjax(deviceStateService.insertDeviceState(deviceState));
    }

    /**
     * 修改设备状态列表
     */
    @RequiresPermissions("device:state:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DeviceState deviceState = deviceStateService.selectDeviceStateById(id);
        mmap.put("deviceState", deviceState);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备状态列表
     */
    @RequiresPermissions("device:state:edit")
    @Log(title = "设备状态列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DeviceState deviceState)
    {
        return toAjax(deviceStateService.updateDeviceState(deviceState));
    }

    /**
     * 删除设备状态列表
     */
    @RequiresPermissions("device:state:remove")
    @Log(title = "设备状态列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(deviceStateService.deleteDeviceStateByIds(ids));
    }
}
